<?php

require "functions/init.php";

// Show welcome message
$log->print_message("AutoSorter cli is running v{$ver['autosorter']['major']}.{$ver['autosorter']['minor']}, db v{$ver['db']['major']}.{$ver['db']['minor']}!\n");

$time = (int) $config["Options"]["run_seconds"];
$time_count = 0;
// Run upgrade
    $upgrade->check_upgrade($db, $config, $ver);
while (1 == 1) {
// Run subtitle download
    $subtitle->find_subtitles();
// Run sorting
    $sort_main->run();
// Run torents
    $torrent->run();
// Finished
    $log->print_message("Sorter job is done!\n");
// Timer
    if ($time == 0)
        die("0 Timer, ending script!");
    while ($time_count < $time) {
        print $time - $time_count . " seconds left\n";
        sleep(1);
        $time_count++;
    }
    $time_count = 0;
}

$db->close;
$log->print_message("Sorter is ended!\n");
?>